<?php
class MetrosController extends AppController {

	var $name = 'Metros';
	var $helpers = array('Form');
	var $uses = array('Metro', 'Pothole', 'Town');
	
	// Cookies:
	function beforeFilter() {
		$this->cookieMonster();
	}

	function index()
		{
			 $this->set('metros', $this->Metro->find('all'));
			 print_r($this->Cookie->read());
		}

	function modify()
		{
		if (!empty($this->data['Metro']))
			{
				$this->data['Metro']['ID'] = $this->Uuid->generate();
				if($this->Metro->save($this->data['Metro']))
					{
						$this->flash('Your Metro has been updated.','/metros/');
					}
			}
		}
		
	function add()
		{
		if (!empty($this->data['Metro']))
			{
				$this->data['Metro']['ID'] = $this->Uuid->generate();
				if($this->Metro->save($this->data['Metro']))
					{
						$this->flash('Your Metro has been updated.','/metros/');
					}
			}
		}
		
	function delete()
		{
		print('This is the delete action.');
		}
		
	function view($host_name) {
			$this->Metro->host_name = $host_name;
			$this->Metro->info = $this->Metro->find('first', array('conditions' => array('Metro.host_name' => $host_name)));
			$this->set('data', $this->Metro->info);
			$this->set('potholes', $this->Pothole->getPotholesByMetro($this->Metro->info['Metro']['ID']) );
			$this->set('towns', $this->Town->getTowns($this->Metro->info['Metro']['ID']));
			// Set or update the Metro value of our cookie
			// $this->Cookie->write('metro.id', $this->Metro->info['Metro']['ID'], true, '+2 days');
			// $this->Cookie->del('town.id');
			print_r($this->Cookie->read());
			$this->set('cookie_data', $this->Cookie->read());
		}

}
?>
